package com.tencent.sr.iris.activity.service.task.impl;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.tencent.sr.bizmid.user.core.interfaces.dto.ChannelUserIdentifyDTO;
import com.tencent.sr.bizmid.user.core.interfaces.dto.UserChannelAccountDTO;
import com.tencent.sr.bizmid.user.core.interfaces.enums.UserGroup;
import com.tencent.sr.bizmid.user.core.interfaces.request.BatchQueryChannelAccountRequest;
import com.tencent.sr.bizmid.user.core.interfaces.response.ChannelAccountQueryResponse;
import com.tencent.sr.iris.activity.common.config.IrisThreadPoolConfig;
import com.tencent.sr.iris.activity.common.constant.QuFaHttpConstant;
import com.tencent.sr.iris.activity.common.enums.IsAdviserEnum;
import com.tencent.sr.iris.activity.common.enums.StaffFromTypeEnum;
import com.tencent.sr.iris.activity.common.enums.TaskStatusEnum;
import com.tencent.sr.iris.activity.common.exception.BizCommErrorCode;
import com.tencent.sr.iris.activity.common.util.AssertUtils;
import com.tencent.sr.iris.activity.dependency.GroupTaskBoardDependency;
import com.tencent.sr.iris.activity.dependency.qufa.GroupTaskBoardNewDependency;
import com.tencent.sr.iris.activity.dependency.user.UserCoreDependency;
import com.tencent.sr.iris.activity.interfaces.request.group.*;
import com.tencent.sr.iris.activity.interfaces.response.group.*;
import com.tencent.sr.iris.activity.interfaces.response.group.operate.OperateSecondBoardResponse;
import com.tencent.sr.iris.activity.service.task.GroupTaskBoardService;
import com.tencent.sr.iris.user.core.service.interfaces.dto.IrisUserInfoDTO;
import com.tencent.sr.iris.user.core.service.interfaces.dto.tutor.UserTutorRelationDTO;
import com.tencent.sr.iris.user.core.service.interfaces.enums.UserLevelEnum;
import com.tencent.sr.iris.user.core.service.interfaces.request.tutor.StudentQueryRequest;
import com.tencent.sr.iris.user.core.service.interfaces.response.user.UserInfoQueryResponse;
import com.tencent.sr.rmall.common.exception.retail.TRetailBizException;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;

@Slf4j
@Component
public class GroupTaskBoardServiceImpl implements GroupTaskBoardService {

    @Resource
    private UserCoreDependency userCoreDependency;

    @Resource
    private GroupTaskBoardDependency groupTaskBoardDependency;

    @Resource(name = IrisThreadPoolConfig.IRIS_QUERY_EXECUTOR)
    private ExecutorService queryExecutor;

    @Resource
    private GroupTaskBoardNewDependency groupTaskBoardNewDependency;

    @Override
    public PaginationResponse<GroupTaskBoardResponse> queryGroupTaskBoard(PaginationRequest<GroupTaskRequest> request) {
        if (!checkGroup(request.getQueryCriteria().getUid())) {
            throw new TRetailBizException(BizCommErrorCode.CHECK_GROUP_IDENTITY);
        }
        return groupTaskBoardDependency.groupTaskBoard(request, QuFaHttpConstant.GROUP_TASK_BOARD);
    }

    @Override
    public PaginationResponse<GroupTaskBoardSecondResponse> queryGroupSecondTaskBoard(
            PaginationRequest<GroupTaskSecondRequest> request) {
        PaginationResponse<GroupTaskBoardSecondResponse> result = groupTaskBoardDependency.groupTaskSecondBoard(
                request, QuFaHttpConstant.GROUP_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupTaskBoardSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<GroupNormalTaskSecondResponse> queryGroupTaskSecondBoardNormal(
            PaginationRequest<GroupTaskSecondRequest> request) {
        PaginationResponse<GroupNormalTaskSecondResponse> result = groupTaskBoardNewDependency.queryNormalTaskBoard(
                request, QuFaHttpConstant.GROUP_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupNormalTaskSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<AdvisorBoardResponse> queryAdvisorBoard(
            PaginationRequest<AdvisorGroupTaskRequest> request) {
        //导师身份进行身份校验
        Integer isAdviser = Optional.ofNullable(
                request.getQueryCriteria().getIsAdviser()).orElse(1);
        String uid = request.getQueryCriteria().getUid();
        isAdviser(isAdviser, uid);
        //默认查询进行中和已结束状态
        if (CollectionUtils.isEmpty(request.getQueryCriteria().getTaskPhaseStatus())) {
            request.getQueryCriteria().setTaskPhaseStatus(Arrays.asList(TaskStatusEnum.BE_ONLINE.getStatus(),
                    TaskStatusEnum.OFFLINE.getStatus()));
        }
        PaginationResponse<AdvisorBoardResponse> result = groupTaskBoardDependency.queryAdvisorBoard(
                request, QuFaHttpConstant.ADVISOR_BOARD);
        List<AdvisorBoardResponse> dataList = result.getDataList();
        if (!CollectionUtils.isEmpty(dataList)) {
            List<Integer> collect = dataList.stream().map(abr -> abr.getTaskPhaseId()).collect(Collectors.toList());
            CanJoinTaskRequest canJoinTaskRequest = new CanJoinTaskRequest();
            canJoinTaskRequest.setTaskPhaseIds(collect);
            if (IsAdviserEnum.ADVISER.getStatus().equals(isAdviser)) {
                canJoinTaskRequest.setUserTutorUid(uid);
            }
            Map<Integer, Integer> map = groupTaskBoardNewDependency.queryCanJoinTaskCount(
                    canJoinTaskRequest, QuFaHttpConstant.LIST_CAN_JOIN_TASK_COUNT);
            if (!map.isEmpty()) {
                result.getDataList().forEach(abr -> {
                    Integer canJoinCount = map.get(abr.getTaskPhaseId());
                    if (Objects.nonNull(canJoinCount) && canJoinCount > 0) {
                        Integer joinCount = abr.getTaskPhaseLeaderJoinCount();
                        Double joinCountRate = (double) joinCount / canJoinCount * 100;
                        BigDecimal bigDecimal = new BigDecimal(joinCountRate);
                        abr.setCanJoinTaskCount(canJoinCount);
                        abr.setJoinTaskRate(bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    }
                });
            }
        }
        return result;
    }

    @Override
    public GroupTaskPaginationResponse<OperateSecondBoardResponse> queryAdvisorSecondBoard(
            PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        //导师身份进行身份校验
        Integer isAdviser = Optional.ofNullable(
                request.getQueryCriteria().getIsAdviser()).orElse(1);
        String uid = request.getQueryCriteria().getUid();
        isAdviser(isAdviser, uid);
        GroupTaskPaginationResponse<OperateSecondBoardResponse> result = groupTaskBoardDependency
                .queryAdvisorSecondBoard(request, QuFaHttpConstant.ADVISOR_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<OperateSecondBoardResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<AdvisorBoardInviteSecondResponse> queryAdvisorSecondBoardInvite(
            PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        //导师身份进行身份校验
        Integer isAdviser = Optional.ofNullable(
                request.getQueryCriteria().getIsAdviser()).orElse(1);
        String uid = request.getQueryCriteria().getUid();
        isAdviser(isAdviser, uid);
        PaginationResponse<AdvisorBoardInviteSecondResponse> result = groupTaskBoardDependency
                .queryAdvisorSecondBoardInvite(request, QuFaHttpConstant.ADVISOR_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<AdvisorBoardInviteSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public GroupTaskPaginationResponse<AdvisorBoardSprintSecondResponse> queryAdvisorSecondBoardSprint(
            PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        //导师身份进行身份校验
        Integer isAdviser = Optional.ofNullable(
                request.getQueryCriteria().getIsAdviser()).orElse(1);
        String uid = request.getQueryCriteria().getUid();
        isAdviser(isAdviser, uid);
        GroupTaskPaginationResponse<AdvisorBoardSprintSecondResponse> result = groupTaskBoardDependency
                .queryAdvisorSecondBoardSprint(request, QuFaHttpConstant.ADVISOR_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<AdvisorBoardSprintSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<AdvisorBoardCommissionSecondResponse> queryAdvisorSecondBoardCommission(
            PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        //导师身份进行身份校验
        Integer isAdviser = Optional.ofNullable(
                request.getQueryCriteria().getIsAdviser()).orElse(1);
        String uid = request.getQueryCriteria().getUid();
        isAdviser(isAdviser, uid);
        PaginationResponse<AdvisorBoardCommissionSecondResponse> result = groupTaskBoardDependency
                .queryAdvisorSecondBoardCommission(request, QuFaHttpConstant.ADVISOR_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<AdvisorBoardCommissionSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<AdvisorBoardFirstOrderSecondResponse> queryAdvisorSecondBoardFirstOrder(
            PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        boolean advisor = checkAdvisor(request.getQueryCriteria().getUid());
        AssertUtils.isTrue(advisor, BizCommErrorCode.CHECK_ADVISOR_IDENTITY);
        PaginationResponse<AdvisorBoardFirstOrderSecondResponse> result = groupTaskBoardDependency
                .queryAdvisorSecondBoardFirstOrder(request, QuFaHttpConstant.ADVISOR_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<AdvisorBoardFirstOrderSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<AdvisorNormalTaskSecondResponse> queryAdvisorSecondBoardNormal(
            PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        boolean advisor = checkAdvisor(request.getQueryCriteria().getUid());
        AssertUtils.isTrue(advisor, BizCommErrorCode.CHECK_ADVISOR_IDENTITY);
        PaginationResponse<AdvisorNormalTaskSecondResponse> result = groupTaskBoardNewDependency
                .queryAdvisorNormalTaskBoard(request, QuFaHttpConstant.ADVISOR_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<AdvisorNormalTaskSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<AdvisorBoardRankSecondResponse> queryAdvisorSecondRank(
            PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        PaginationResponse<AdvisorBoardRankSecondResponse> result = groupTaskBoardDependency.queryAdvisorSecondRank(
                request, QuFaHttpConstant.ADVISOR_TASK_SECOND);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<AdvisorBoardRankSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<GroupTaskBoardSecondResponse> queryAdvisorThirdBoard(
            PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        PaginationResponse<GroupTaskBoardSecondResponse> result = groupTaskBoardDependency.queryAdvisorThirdBoard(
                request, QuFaHttpConstant.ADVISOR_TASK_THIRD);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupTaskBoardSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<GroupTaskBoardSecondResponse> queryAdvisorThirdBoardInvite(
            PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        PaginationResponse<GroupTaskBoardSecondResponse> result = groupTaskBoardDependency.queryAdvisorThirdBoard(
                request, QuFaHttpConstant.ADVISOR_TASK_THIRD);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupTaskBoardSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<GroupTaskBoardSecondResponse> queryAdvisorThirdBoardFirstOrder(
            PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        PaginationResponse<GroupTaskBoardSecondResponse> result = groupTaskBoardDependency
                .queryAdvisorThirdBoard(request, QuFaHttpConstant.ADVISOR_TASK_THIRD);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupTaskBoardSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<GroupTaskBoardSecondResponse> queryAdvisorThirdBoardSprint(
            PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        PaginationResponse<GroupTaskBoardSecondResponse> result = groupTaskBoardDependency.queryAdvisorThirdBoard(
                request, QuFaHttpConstant.ADVISOR_TASK_THIRD);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupTaskBoardSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<AdvisorBoardCommissionThirdResponse> queryAdvisorThirdBoardCommission(
            PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        PaginationResponse<AdvisorBoardCommissionThirdResponse> result = groupTaskBoardDependency
                .queryAdvisorThirdBoardCommission(request, QuFaHttpConstant.ADVISOR_TASK_THIRD);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<AdvisorBoardCommissionThirdResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<GroupNormalTaskSecondResponse> queryAdvisorThirdBoardNormal(
            PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        PaginationResponse<GroupNormalTaskSecondResponse> result = groupTaskBoardNewDependency
                .queryAdvisorNormalThirdBoard(request, QuFaHttpConstant.ADVISOR_TASK_THIRD);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupNormalTaskSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public PaginationResponse<GroupTaskBoardSecondResponse> queryAdvisorThirdRank(
            PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        PaginationResponse<GroupTaskBoardSecondResponse> result = groupTaskBoardDependency.queryAdvisorThirdBoard(
                request, QuFaHttpConstant.ADVISOR_TASK_THIRD);
        if (!CollectionUtils.isEmpty(result.getDataList())) {
            List<GroupTaskBoardSecondResponse> dataList = result.getDataList();
            dataList.stream().forEach(r -> {
                String irisUid = r.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO user = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    r.setWechatUserUnionid(user.getUnionId());
                }
            });
        }
        return result;
    }

    @Override
    public TaskStatisticsResponse queryAdvisorTaskStatistics(TaskStatisticsRequest request) {
        return groupTaskBoardNewDependency.queryTaskStatistics(request, QuFaHttpConstant.ADVISOR_TASK_STATISTICS);
    }

    @Override
    public TaskStatisticsResponse querySellerTaskStatistics(TaskStatisticsRequest request) {
        return groupTaskBoardNewDependency.queryTaskStatistics(request, QuFaHttpConstant.SELLER_TASK_STATISTICS);
    }

    @Override
    public List<RankAwardConfigResponse> queryRankConfigs(RankConfigRequest request) {
        return groupTaskBoardDependency.queryRankConfigs(request, QuFaHttpConstant.LIST_RANK_AWARD_CONFIG);
    }


    /**
     * 判断身份是否为团长
     *
     * @param uid
     * @return
     */
    public Boolean checkGroup(String uid) {
        if (StringUtils.isEmpty(uid)) {
            throw new TRetailBizException("uid不能为空！");
        }
        UserInfoQueryResponse userInfoQueryResponse = userCoreDependency.queryUserInfo(uid, false);
        IrisUserInfoDTO irisUserInfo = userInfoQueryResponse.getUserInfoDTO();
        if (irisUserInfo != null) {
            String levelId = irisUserInfo.getLevelId();
            Byte type = irisUserInfo.getType();
            if (Objects.nonNull(levelId) && Objects.nonNull(type)) {
                //见习会员及以上等级的外部用户 为团长
                if (StaffFromTypeEnum.isOuterSign(type.toString()) && UserLevelEnum.GROUP_LIST.contains(levelId)) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 判断身份是否为导师
     *
     * @param uid
     * @return
     */
    public Boolean checkAdvisor(String uid) {
        if (StringUtils.isEmpty(uid)) {
            throw new TRetailBizException("uid不能为空！");
        }
        UserInfoQueryResponse userInfoQueryResponse = userCoreDependency.queryUserInfo(uid, false);
        IrisUserInfoDTO irisUserInfo = userInfoQueryResponse.getUserInfoDTO();
        if (irisUserInfo != null) {
            Byte type = irisUserInfo.getType();
            if (Objects.nonNull(type)) {
                if (StaffFromTypeEnum.TUTOR.getCode().equals(type.toString())) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 根据导师uid查询下面关联的团长unionIds
     *
     * @param uid
     * @return
     */
    public List<String> getTutorRelations(String uid, Long saasId) {
        if (StringUtils.isEmpty(uid)) {
            throw new TRetailBizException("uid不能为空！");
        }
        PaginationRequest<StudentQueryRequest> paginationRequest = new PaginationRequest<>();
        StudentQueryRequest studentQueryRequest = new StudentQueryRequest();
        studentQueryRequest.setTutorUid(uid);
        paginationRequest.setQueryCriteria(studentQueryRequest);
        paginationRequest.setPageSize(1000);
        paginationRequest.setPageNum(1);
        PaginationResponse<UserTutorRelationDTO> userTutorRelations = userCoreDependency.queryTutorStudentList(
                paginationRequest);
        List<String> list = new ArrayList<>();
        final int segment = 10;
        if (!CollectionUtils.isEmpty(userTutorRelations.getDataList())) {
            List<String> collect = userTutorRelations.getDataList().stream().map(user -> user.getUid())
                    .collect(Collectors.toList());
            int size = collect.size();
            log.info("GroupTaskBoardServiceImpl getTutorRelations size:{},result:{}", size, JSON.toJSONString(collect));
            try {
                List<CompletableFuture<ChannelAccountQueryResponse>> futures = new ArrayList<>();
                List<List<String>> partition = Lists.partition(collect, segment);
                for (List<String> part : partition) {
                    BatchQueryChannelAccountRequest request = new BatchQueryChannelAccountRequest();
                    request.setSaasId(saasId);
                    request.setUserGroup(UserGroup.GROUP_C.getType());
                    request.setUidList(part);
                    futures.add(CompletableFuture.supplyAsync(() ->
                                    userCoreDependency.batchQueryChannelAccount(request).getData(),
                            queryExecutor));
                }
                for (CompletableFuture<ChannelAccountQueryResponse> channelAccount : futures) {
                    ChannelAccountQueryResponse channelAccountQueryResponse = channelAccount.get();
                    if (Objects.nonNull(channelAccountQueryResponse)) {
                        List<UserChannelAccountDTO> userChannelAccountDTOS = channelAccountQueryResponse
                                .getChannelAccountDTOList();
                        if (!CollectionUtils.isEmpty(userChannelAccountDTOS)) {
                            for (UserChannelAccountDTO userChannelAccountDTO : userChannelAccountDTOS) {
                                ChannelUserIdentifyDTO userIdentifyDTO = userChannelAccountDTO
                                        .getChannelUserIdentifyDTO();
                                if (userIdentifyDTO != null && !StringUtils.isEmpty(userIdentifyDTO.getUnionId())) {
                                    list.add(userIdentifyDTO.getUnionId());
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                log.error("查询导师对应团长unionId出错，导师uid:{}", uid, e);
                throw new TRetailBizException("导师uid:{},查询团长unionId出错", uid);
            }
        }
        List<String> result = list.stream().distinct().collect(Collectors.toList());
        log.info("导师uid:{},GroupTaskBoardServiceImpl queryGroupUnionId result:{}", uid, result);
        return result;
    }

    public boolean isAdviser(int isAdviser, String uid) {
        //前端没有传值时，默认要校验导师身份
        if (IsAdviserEnum.ADVISER.getStatus().equals(isAdviser)) {
            if (!checkAdvisor(uid)) {
                throw new TRetailBizException(BizCommErrorCode.CHECK_ADVISOR_IDENTITY);
            }
            return true;
        }
        return false;
    }

}
